# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

# 递归

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        def is_sym(node1, node2):
            if node1 == node2:
                return True
            if node1 and node2:
                return node1.val == node2.val and is_sym(node1.left, node2.right) and is_sym(node1.right, node2.left)
            return False

        return is_sym(root.left, root.right) if root else True